import { defineStore } from "pinia";
interface GoodsType {
  name: string;
  price: number;
}
export const useGoods = defineStore("goods", {
  state: () => ({
    list: [
      { name: "商品1", price: 9999 },
      { name: "商品2", price: 999.9 },
      { name: "商品3", price: 99.99 },
    ],
  }),
  getters: {
    filterList(state): Array<GoodsType> {
      return state.list.filter((item) => item.price > 500);
    },
  },
  actions: {
    // 同步action，只操作本地数据
    addGoods(newGoods: GoodsType) {
      this.list.push(newGoods);
    },
  },
  persist: true,
});
